package com.sxau.software_educational_system_backend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxau.software_educational_system_backend.annotation.AdminOneOrTwo;
import com.sxau.software_educational_system_backend.annotation.AdminOnlyOne;
import com.sxau.software_educational_system_backend.annotation.AdminOnlyTwo;
import com.sxau.software_educational_system_backend.common.BaseResponse;
import com.sxau.software_educational_system_backend.common.ResultUtils;
import com.sxau.software_educational_system_backend.domain.entity.WorkerStudent;
import com.sxau.software_educational_system_backend.service.WorkerStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/worker")
@RequiredArgsConstructor
@Api(tags = "就业学生信息管理接口")
public class WorkerStudentController {
    private final WorkerStudentService workerStudentService;

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询就业学生详情")
    public BaseResponse<WorkerStudent> getById(@PathVariable Integer id) {
        return ResultUtils.success(workerStudentService.getById(id));
    }

    @PostMapping("/yz")
    @ApiOperation("新增就业学生信息")
    @AdminOneOrTwo
    public BaseResponse<WorkerStudent> create(@RequestBody WorkerStudent workerStudent) {
        workerStudentService.save(workerStudent);
        return ResultUtils.success(workerStudent);
    }

    @DeleteMapping("/yz/{id}")
    @ApiOperation("删除就业学生信息")
    @AdminOneOrTwo
    public BaseResponse<Void> delete(@PathVariable Integer id) {
        workerStudentService.removeById(id);
        return ResultUtils.success();
    }

    @GetMapping
    @ApiOperation("获取所有就业学生列表")
    public BaseResponse<List<WorkerStudent>> getAll() {
        return ResultUtils.success(workerStudentService.list());
    }

    @PutMapping("/yz/{id}")
    @ApiOperation("更新就业学生信息")
    @AdminOneOrTwo
    public BaseResponse<WorkerStudent> update(@PathVariable Integer id,@RequestBody WorkerStudent workerStudent) {
        workerStudent.setId(id);
        workerStudentService.updateById(workerStudent);
        return ResultUtils.success(workerStudentService.getById(id));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询就业学生信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10")
    })
    public BaseResponse<Page<WorkerStudent>> getPage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<WorkerStudent> workerStudentPage = new Page<>(page, pageSize);
        return ResultUtils.success(workerStudentService.page(workerStudentPage));
    }
}
